import Vue from 'vue'
import App from './App.vue'
import store from '@/store/index'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

import router from './router/index.js'

router.beforeEach((to,from,next)=>{
    if(to.meta.title){
        document.title = to.meta.title;
    }
    next()
})

//moment.js
var moment=require('moment');
moment().format();

Vue.config.productionTip = false
new Vue({
  render: h => h(App),
    router,
    store
}).$mount('#app')


Vue.filter("dateFormat", function (dateStr, type) {
    var date = new Date(dateStr);
    //yyyy-mm-dd
    var year = date.getFullYear();
    var month = (date.getMonth() + 1).toString().padStart(2, "0");
    var day = date.getDate().toString().padStart(2, "0");
    if (type == "yyyy-mm-dd") {
        return `${year}-${month}-${day}`;
    } else {
        var hour = date.getHours().toString().padStart(2, "0");
        var minus = date.getMinutes().toString().padStart(2, "0");
        var second = date.getSeconds().toString().padStart(2, "0");
        return `${year}-${month}-${day} ${hour}:${minus}:${second}`;
    }
})

Vue.filter("dateFormat2", function (dateStr, type) {
    var date = new Date(dateStr);
    //yyyy-mm-dd
    var year = date.getFullYear();
    var month = (date.getMonth() + 1).toString().padStart(2, "0");
    var day = date.getDate().toString().padStart(2, "0");
    if (type == "yyyy-mm-dd") {
        return `${year}-${month}-${day}`;
    } else {
        var hour = date.getHours().toString().padStart(2, "0");
        var minus = date.getMinutes().toString().padStart(2, "0");
        var second = date.getSeconds().toString().padStart(2, "0");
        return `${year}年${month}月${day}日`;
    }
})
    Vue.filter("dateFormat3", function (dateStr, type) {
        var date = new Date(dateStr);
        //yyyy-mm-dd
        var year = date.getFullYear();
        var month = (date.getMonth() + 1).toString().padStart(2, "0");
        var day = date.getDate().toString().padStart(2, "0");
        if (type == "yyyy-mm-dd") {
            return `${year}-${month}-${day}`;
        } else {
            var hour = date.getHours().toString().padStart(2, "0");
            var minus = date.getMinutes().toString().padStart(2, "0");
            var second = date.getSeconds().toString().padStart(2, "0");
            return `${year}-${month}-${day}`;
        }
})